<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>numpy.set_printoptions &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <script type="text/javascript" src="../../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../../about.html" >
    <link rel="index" title="Index" href="../../genindex.html" >
    <link rel="search" title="Search" href="../../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../../index.html" >
    <link rel="up" title="Input and output" href="../routines.io.html" >
    <link rel="next" title="numpy.get_printoptions" href="numpy.get_printoptions.html" >
    <link rel="prev" title="numpy.format_float_scientific" href="numpy.format_float_scientific.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../../index.html">
      <img border=0 alt="NumPy" src="../../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="../index.html" >NumPy Reference</a></li>
          <li class="active"><a href="../routines.html" >Routines</a></li>
          <li class="active"><a href="../routines.io.html" accesskey="U">Input and output</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="numpy.get_printoptions.html" title="numpy.get_printoptions"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="numpy.format_float_scientific.html" title="numpy.format_float_scientific"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="numpy.format_float_scientific.html"
                        title="previous chapter">numpy.format_float_scientific</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="numpy.get_printoptions.html"
                        title="next chapter">numpy.get_printoptions</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="numpy-set-printoptions">
<h1>numpy.set_printoptions<a class="headerlink" href="#numpy-set-printoptions" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="numpy.set_printoptions">
<code class="sig-prename descclassname">numpy.</code><code class="sig-name descname">set_printoptions</code><span class="sig-paren">(</span><em class="sig-param">precision=None</em>, <em class="sig-param">threshold=None</em>, <em class="sig-param">edgeitems=None</em>, <em class="sig-param">linewidth=None</em>, <em class="sig-param">suppress=None</em>, <em class="sig-param">nanstr=None</em>, <em class="sig-param">infstr=None</em>, <em class="sig-param">formatter=None</em>, <em class="sig-param">sign=None</em>, <em class="sig-param">floatmode=None</em>, <em class="sig-param">**kwarg</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/numpy/numpy/blob/v1.18.1/numpy/core/arrayprint.py#L100-L270"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numpy.set_printoptions" title="Permalink to this definition">¶</a></dt>
<dd><p>Set printing options.</p>
<p>These options determine the way floating point numbers, arrays and
other NumPy objects are displayed.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl>
<dt><strong>precision</strong><span class="classifier">int or None, optional</span></dt><dd><p>Number of digits of precision for floating point output (default 8).
May be None if <em class="xref py py-obj">floatmode</em> is not <em class="xref py py-obj">fixed</em>, to print as many digits as
necessary to uniquely specify the value.</p>
</dd>
<dt><strong>threshold</strong><span class="classifier">int, optional</span></dt><dd><p>Total number of array elements which trigger summarization
rather than full repr (default 1000).
To always use the full repr without summarization, pass <a class="reference external" href="https://docs.python.org/dev/library/sys.html#sys.maxsize" title="(in Python v3.9)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sys.maxsize</span></code></a>.</p>
</dd>
<dt><strong>edgeitems</strong><span class="classifier">int, optional</span></dt><dd><p>Number of array items in summary at beginning and end of
each dimension (default 3).</p>
</dd>
<dt><strong>linewidth</strong><span class="classifier">int, optional</span></dt><dd><p>The number of characters per line for the purpose of inserting
line breaks (default 75).</p>
</dd>
<dt><strong>suppress</strong><span class="classifier">bool, optional</span></dt><dd><p>If True, always print floating point numbers using fixed point
notation, in which case numbers equal to zero in the current precision
will print as zero.  If False, then scientific notation is used when
absolute value of the smallest number is &lt; 1e-4 or the ratio of the
maximum absolute value to the minimum is &gt; 1e3. The default is False.</p>
</dd>
<dt><strong>nanstr</strong><span class="classifier">str, optional</span></dt><dd><p>String representation of floating point not-a-number (default nan).</p>
</dd>
<dt><strong>infstr</strong><span class="classifier">str, optional</span></dt><dd><p>String representation of floating point infinity (default inf).</p>
</dd>
<dt><strong>sign</strong><span class="classifier">string, either ‘-‘, ‘+’, or ‘ ‘, optional</span></dt><dd><p>Controls printing of the sign of floating-point types. If ‘+’, always
print the sign of positive values. If ‘ ‘, always prints a space
(whitespace character) in the sign position of positive values.  If
‘-‘, omit the sign character of positive values. (default ‘-‘)</p>
</dd>
<dt><strong>formatter</strong><span class="classifier">dict of callables, optional</span></dt><dd><p>If not None, the keys should indicate the type(s) that the respective
formatting function applies to.  Callables should return a string.
Types that are not specified (by their corresponding keys) are handled
by the default formatters.  Individual types for which a formatter
can be set are:</p>
<ul class="simple">
<li><p>‘bool’</p></li>
<li><p>‘int’</p></li>
<li><p>‘timedelta’ : a <code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.timedelta64</span></code></p></li>
<li><p>‘datetime’ : a <code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.datetime64</span></code></p></li>
<li><p>‘float’</p></li>
<li><p>‘longfloat’ : 128-bit floats</p></li>
<li><p>‘complexfloat’</p></li>
<li><p>‘longcomplexfloat’ : composed of two 128-bit floats</p></li>
<li><p>‘numpystr’ : types <code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.string_</span></code> and <code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.unicode_</span></code></p></li>
<li><p>‘object’ : <em class="xref py py-obj">np.object_</em> arrays</p></li>
<li><p>‘str’ : all other strings</p></li>
</ul>
<p>Other keys that can be used to set a group of types at once are:</p>
<ul class="simple">
<li><p>‘all’ : sets all types</p></li>
<li><p>‘int_kind’ : sets ‘int’</p></li>
<li><p>‘float_kind’ : sets ‘float’ and ‘longfloat’</p></li>
<li><p>‘complex_kind’ : sets ‘complexfloat’ and ‘longcomplexfloat’</p></li>
<li><p>‘str_kind’ : sets ‘str’ and ‘numpystr’</p></li>
</ul>
</dd>
<dt><strong>floatmode</strong><span class="classifier">str, optional</span></dt><dd><p>Controls the interpretation of the <em class="xref py py-obj">precision</em> option for
floating-point types. Can take the following values
(default maxprec_equal):</p>
<ul class="simple">
<li><dl class="simple">
<dt>‘fixed’: Always print exactly <em class="xref py py-obj">precision</em> fractional digits,</dt><dd><p>even if this would print more or fewer digits than
necessary to specify the value uniquely.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>‘unique’: Print the minimum number of fractional digits necessary</dt><dd><p>to represent each value uniquely. Different elements may
have a different number of digits. The value of the
<em class="xref py py-obj">precision</em> option is ignored.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>‘maxprec’: Print at most <em class="xref py py-obj">precision</em> fractional digits, but if</dt><dd><p>an element can be uniquely represented with fewer digits
only print it with that many.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>‘maxprec_equal’: Print at most <em class="xref py py-obj">precision</em> fractional digits,</dt><dd><p>but if every element in the array can be uniquely
represented with an equal number of fewer digits, use that
many digits for all elements.</p>
</dd>
</dl>
</li>
</ul>
</dd>
<dt><strong>legacy</strong><span class="classifier">string or <em class="xref py py-obj">False</em>, optional</span></dt><dd><p>If set to the string <em class="xref py py-obj">‘1.13’</em> enables 1.13 legacy printing mode. This
approximates numpy 1.13 print output by including a space in the sign
position of floats and different behavior for 0d arrays. If set to
<em class="xref py py-obj">False</em>, disables legacy mode. Unrecognized strings will be ignored
with a warning for forward compatibility.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 1.14.0.</span></p>
</div>
</dd>
</dl>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="numpy.get_printoptions.html#numpy.get_printoptions" title="numpy.get_printoptions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_printoptions</span></code></a>, <a class="reference internal" href="numpy.printoptions.html#numpy.printoptions" title="numpy.printoptions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">printoptions</span></code></a>, <a class="reference internal" href="numpy.set_string_function.html#numpy.set_string_function" title="numpy.set_string_function"><code class="xref py py-obj docutils literal notranslate"><span class="pre">set_string_function</span></code></a>, <a class="reference internal" href="numpy.array2string.html#numpy.array2string" title="numpy.array2string"><code class="xref py py-obj docutils literal notranslate"><span class="pre">array2string</span></code></a></p>
</div>
<p class="rubric">Notes</p>
<p><a class="reference external" href="https://docs.python.org/dev/library/formatter.html#module-formatter" title="(in Python v3.9)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">formatter</span></code></a> is always reset with a call to <a class="reference internal" href="#numpy.set_printoptions" title="numpy.set_printoptions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">set_printoptions</span></code></a>.</p>
<p>Use <a class="reference internal" href="numpy.printoptions.html#numpy.printoptions" title="numpy.printoptions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">printoptions</span></code></a> as a context manager to set the values temporarily.</p>
<p class="rubric">Examples</p>
<p>Floating point precision can be set:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">set_printoptions</span><span class="p">(</span><span class="n">precision</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.123456789</span><span class="p">])</span>
<span class="go">[1.1235]</span>
</pre></div>
</div>
<p>Long arrays can be summarised:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">set_printoptions</span><span class="p">(</span><span class="n">threshold</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">array([0, 1, 2, ..., 7, 8, 9])</span>
</pre></div>
</div>
<p>Small results can be suppressed:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eps</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">finfo</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span><span class="o">.</span><span class="n">eps</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">4.</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">eps</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
<span class="go">array([-4.9304e-32, -4.4409e-16,  0.0000e+00,  0.0000e+00])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">set_printoptions</span><span class="p">(</span><span class="n">suppress</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">eps</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
<span class="go">array([-0., -0.,  0.,  0.])</span>
</pre></div>
</div>
<p>A custom formatter can be used to display array elements as desired:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">set_printoptions</span><span class="p">(</span><span class="n">formatter</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;all&#39;</span><span class="p">:</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="s1">&#39;int: &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="p">)})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([int: 0, int: -1, int: -2])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">set_printoptions</span><span class="p">()</span>  <span class="c1"># formatter gets reset</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([0, 1, 2])</span>
</pre></div>
</div>
<p>To put back the default options, you can use:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">set_printoptions</span><span class="p">(</span><span class="n">edgeitems</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">infstr</span><span class="o">=</span><span class="s1">&#39;inf&#39;</span><span class="p">,</span>
<span class="gp">... </span><span class="n">linewidth</span><span class="o">=</span><span class="mi">75</span><span class="p">,</span> <span class="n">nanstr</span><span class="o">=</span><span class="s1">&#39;nan&#39;</span><span class="p">,</span> <span class="n">precision</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
<span class="gp">... </span><span class="n">suppress</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">threshold</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="n">formatter</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
</pre></div>
</div>
<p>Also to temporarily override options, use <a class="reference internal" href="numpy.printoptions.html#numpy.printoptions" title="numpy.printoptions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">printoptions</span></code></a> as a context manager:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">np</span><span class="o">.</span><span class="n">printoptions</span><span class="p">(</span><span class="n">precision</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">suppress</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">threshold</span><span class="o">=</span><span class="mi">5</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="go">array([ 0.  ,  1.11,  2.22, ...,  7.78,  8.89, 10.  ])</span>
</pre></div>
</div>
</dd></dl>

</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>